<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="检验单编号" prop="oqcCode">
        <el-input
          v-model="queryParams.oqcCode"
          placeholder="请输入出货检验单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次号" prop="batchCode">
        <el-input
          v-model="queryParams.batchCode"
          placeholder="请输入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择检测结果">
            <el-option
              v-for="dict in dict.type.mes_qc_result"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:qc:oqc:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:qc:oqc:edit']"
        >修改</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:qc:oqc:remove']"
        >删除</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:qc:oqc:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="oqcList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="出货检验单编号" width="140" align="center" prop="oqcCode" >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
            v-hasPermi="['mes:qc:oqc:query']"
          >{{scope.row.oqcCode}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="验单名称" align="center" prop="oqcName" :show-overflow-tooltip="true"/>

      <el-table-column label="客户名称" align="center" prop="clientName" :show-overflow-tooltip="true"/>
      <el-table-column label="批次号" width="160" align="center" prop="batchCode" :show-overflow-tooltip="true"/>

      <el-table-column label="产品编码" width="140" align="center" prop="itemCode" />
      <el-table-column label="产品名称" align="center" prop="itemName" :show-overflow-tooltip="true"/>
      <el-table-column label="规格" align="center" prop="specification" :show-overflow-tooltip="true"/>
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
      <el-table-column
        v-for="col in columnsConfig"
        :key="col.prop"
        :label="col.label"
        :prop="col.prop"
        :width="col.width"
        :align="col.align"
        v-if="col.show">
      </el-table-column>
      <el-table-column label="发货数量" align="center" prop="quantityOut" fixed="right">
        <template slot-scope="scope">
          <el-tag type="warning">{{ scope.row.quantityOut }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="检测数量" align="center" prop="quantityCheck" fixed="right">
        <template slot-scope="scope">
          <el-tag >{{ scope.row.quantityCheck }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="不合格数" align="center" prop="quantityUnqualified" fixed="right">
        <template slot-scope="scope">
          <el-tag type="danger">{{ scope.row.quantityUnqualified }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="出货日期" align="center" prop="outDate" width="100px" fixed="right">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测日期" align="center" prop="inspectDate" width="100px" fixed="right">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测人员" align="center" prop="inspector" fixed="right"/>
      <el-table-column label="检测结果" align="center" prop="checkResult" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_qc_result" :value="scope.row.checkResult"/>
        </template>
      </el-table-column>
      <el-table-column label="单据状态" align="center" prop="status" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="160px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:qc:oqc:edit']"
            v-if="scope.row.status === 'PREPARE'"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:qc:oqc:remove']"
            v-if="scope.row.status === 'PREPARE'"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-printer"
            @click="handlePrint(scope.row)"
            v-hasPermi="['mes:qc:oqc:print']"
            v-if="scope.row.status === 'FINISHED' || scope.row.status === 'EXEMPT'"
          >打印</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改出货检验单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="检验单编号" prop="oqcCode">
              <el-input v-model="form.oqcCode" readonly />
            </el-form-item>
          </el-col>

<!--          <el-col :span="4">
            <el-form-item  label-width="80">
              <el-switch v-model="autoGenFlag"
                  active-color="#13ce66"
                  active-text="自动生成"
                  @change="handleAutoGenChange(autoGenFlag)" v-if="optType != 'view' && form.status =='PREPARE'" >
              </el-switch>
            </el-form-item>
          </el-col>-->

          <el-col :span="12">
            <el-form-item label="检验单名称" prop="oqcName">
              <el-input v-model="form.oqcName" :readonly="optType === 'view'" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-if="form.oqcId ==null " readonly v-model="form.itemCode" placeholder="请选择产品" >
                <el-button slot="append" @click="handleSelectProduct" icon="el-icon-search"></el-button>
              </el-input>
              <!--如果已经保存过，则产品不允许再修改，需要修改就删除重做-->
              <el-input v-else v-model="form.itemCode" readonly/>
              <SalseSelect ref="itemSelect" @onSelected="onItemSelected" ></SalseSelect>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="产品名称" prop="itemName">
              <el-input :readonly="optType === 'view'" v-model="form.itemName"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input :readonly="optType === 'view'" v-model="form.unitOfMeasure"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="规格" prop="specification">
              <el-input :readonly="optType === 'view'" v-model="form.specification"  />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="型号" prop="specification">
              <el-input :readonly="optType === 'view'" v-model="form.itemModel" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="颜色" prop="specification">
              <el-input :readonly="optType === 'view'" v-model="form.itemColor"  />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="品牌" prop="specification">
              <el-input :readonly="optType === 'view'" v-model="form.itemBrand"  />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="技术要求" prop="specification">
              <el-input :readonly="optType === 'view'" v-model="form.itemTechReq" />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户编号" prop="clientCode">
              <el-input v-model="form.clientCode" readonly >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="客户名称" prop="clientName">
              <el-input readonly v-model="form.clientName" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="批次号" prop="batchCode">
              <el-input v-model="form.batchCode" readonly />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="发货数量" prop="quantityOut">
              <el-input v-model="form.quantityOut" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检测数量" prop="quantityCheck">
              <el-input-number
                :min="0"
                v-model="form.quantityCheck"
                placeholder="请输入本次检测数量"
                :disabled="optType === 'view'"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="不合格数量" prop="quantityUnqualified">
              <el-input-number
                :min="0"
                v-model="form.quantityUnqualified"
                :disabled="optType === 'view'"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="出货日期" prop="outDate">
              <el-date-picker clearable
                v-model="form.outDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择出货日期"
                :disabled="optType === 'view'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检测日期" prop="inspectDate">
              <el-date-picker clearable
                v-model="form.inspectDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择检测日期"
                :disabled="optType === 'view'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检测结果" prop="checkResult">
              <el-select v-model="form.checkResult" placeholder="请选择检测结果" :disabled="optType === 'view'">
                <el-option
                  v-for="dict in dict.type.mes_qc_result"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                  v-if="(optType === 'view' || dict.value !== 'EXEMPT')"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="检测人员" prop="inspector">
              <el-input v-model="form.inspector" placeholder="请输入检测人员" readonly>
                <el-button
                  slot="append"
                  @click="handleSelectUser"
                  icon="el-icon-search"
                  v-if="optType !== 'view'">
                </el-button>
              </el-input>
              <UserSelect ref="userSelect" @onSelected="onUserSelected" ></UserSelect>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :readonly="optType === 'view'" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">统计结果</el-divider>
          <el-row>
            <el-col :span="8">
              <el-form-item label="致命缺陷数量" prop="crQuantity">
                <el-input readonly v-model="form.crQuantity" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="严重缺陷数量" prop="majQuantity">
                <el-input readonly v-model="form.majQuantity" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="轻微缺陷数量" prop="minQuantity">
                <el-input readonly v-model="form.minQuantity" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="致命缺陷率" prop="crQuantity">
                <el-input readonly v-model="form.crRate" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="严重缺陷率" prop="majRate">
                <el-input readonly v-model="form.majRate" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="轻微缺陷率" prop="minRate">
                <el-input readonly v-model="form.minRate" />
              </el-form-item>
            </el-col>
          </el-row>

      </el-form>
      <el-divider v-if="form.oqcId !=null" content-position="center">检测项</el-divider>
      <el-card shadow="always" v-if="form.oqcId !=null" class="box-card">
          <Oqcline ref=line :oqcId="form.oqcId" :optType="optType" @handleReview="handleReview"></Oqcline>
      </el-card>
      <el-divider v-if="form.oqcId !=null" content-position="center">检测过程</el-divider>
      <el-card shadow="always" v-if="form.oqcId != null" class="box-card">
        <FileUpload
          :limit="1"
          :fileSize="100"
          :fileType="fileType"
          :value="fileList"
          :optType="optType"
          @onUploaded="handleUploaded"
          @onRemoved="handleRemoved">
        </FileUpload>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="optType =='view' || form.status !='PREPARE' ">返回</el-button>
        <el-button type="primary" @click="submitForm" v-if="form.status =='PREPARE' && optType !='view' ">保 存</el-button>
        <el-button type="success" @click="handleFinish" v-if="form.status =='PREPARE' && optType !='view'  && form.oqcId !=null">完成</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <OqcPrint ref="oqcPrint" v-if="printvisible"></OqcPrint>

  </div>
</template>

<script>
import { listOqc, getOqc, delOqc, addOqc, updateOqc } from "@/api/mes/qc/oqc";
import {genCode} from "@/api/system/autocode/rule";
import Oqcline from "./line.vue";
import SalseSelect from "./salseSelect";
import UserSelect from "@/components/userSelect/single.vue";
import { getUserProfile } from "@/api/system/user";
import {getColumnsConfigKey} from "@/api/system/columnsconfig";
import OqcPrint from "./print.vue"

export default {
  name: "Oqc",
  dicts: ['mes_order_status','mes_qc_result'],
  components: {
    Oqcline, SalseSelect, UserSelect, OqcPrint
  },
  data() {
    return {
      //自动生成编码
      autoGenFlag:false,
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出货检验单表格数据
      oqcList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oqcCode: null,
        oqcName: null,
        templateId: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        batchCode: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        unitOfMeasure: null,
        quantityMinCheck: null,
        quantityMaxUnqualified: null,
        quantityOut: null,
        quantityCheck: null,
        quantityUnqualified: null,
        quantityQuanlified: null,
        crRate: null,
        majRate: null,
        minRate: null,
        crQuantity: null,
        majQuantity: null,
        minQuantity: null,
        checkResult: null,
        outDate: null,
        inspectDate: null,
        inspector: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 上传文件类型
      fileType: ["pdf","doc", "xls","jpg","png"],
      // 上传文件列表
      fileList: [],
      // 表单校验
      rules: {
        oqcCode: [
          { required: true, message: "出货检验单编号不能为空", trigger: "blur" }
        ],
        itemCode: [
          { required: true, message: "产品不能为空", trigger: "blur" }
        ],
        quantityCheck: [
          { required: true, message: "本次检测数量不能为空", trigger: "blur" }
        ],
        outDate: [
          { required: true, message: "请选择出货日期", trigger: "blur" }
        ],
        inspectDate: [
          { required: true, message: "请选择检测日期", trigger: "blur" }
        ],
      },
      // 当前登录用户
      user: null,
      columnsConfig:[],
      // 打印开关
      printvisible: false,
    };
  },
  created() {
    this.getList();
    this.getUser();
    this.getItemBase();
  },
  methods: {
    /** 查询出货检验单列表 */
    getList() {
      this.loading = true;
      listOqc(this.queryParams).then(response => {
        this.oqcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getItemBase(){
      getColumnsConfigKey('MdItem_Base').then(res=>{
        this.columnsConfig = JSON.parse(res.data);
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        oqcId: null,
        oqcCode: null,
        oqcName: null,
        templateId: null,
        sourceDocId: null,
        sourceDocType: null,
        sourceDocCode: null,
        sourceLineId: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        batchCode: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        unitOfMeasure: null,
        quantityMinCheck: null,
        quantityMaxUnqualified: null,
        quantityOut: null,
        quantityCheck: null,
        quantityUnqualified: null,
        quantityQuanlified: null,
        crRate: null,
        majRate: null,
        minRate: null,
        crQuantity: null,
        majQuantity: null,
        minQuantity: null,
        checkResult: null,
        outDate: null,
        inspectDate: null,
        inspector: null,
        status: "PREPARE",
        remark: null,
        attr1: null,
        attr2: null,
        attr3: null,
        attr4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.autoGenFlag = false;
      this.resetForm("form");
      this.fileList = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.oqcId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    //查看明细
    handleView(row){
      this.reset();
      const oqcId = row.oqcId || this.ids;
      getOqc(oqcId).then(response => {
        this.form = response.data;
        this.form.attr2 = response.data.attr2;
        response.data.attr2 === null ? this.fileList = [] : this.fileList.push(response.data.attr2);
        this.open = true;
        this.title = "查看出货检验单信息";
        this.optType = "view";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      genCode('OQC_CODE').then(response =>{
        this.form.oqcCode = response;
      });
      this.form.inspector = this.user.nickName;
      this.open = true;
      this.title = "添加出货检验单";
      this.optType = "add";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const oqcId = row.oqcId || this.ids
      getOqc(oqcId).then(response => {
        this.form = response.data;
        this.form.attr2 = response.data.attr2;
        response.data.attr2 === null ? this.fileList = [] : this.fileList.push(response.data.attr2);
        this.open = true;
        this.title = "修改出货检验单";
        this.optType = "edit";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.oqcId != null) {
            updateOqc(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOqc(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //点击完成
    handleFinish(){
      let that = this;
      if(this.form.checkResult == null){
        this.$modal.msgError("请选择检测结果！");
        return;
      }

      let out = parseInt(that.form.quantityOut);
      if (that.form.quantityCheck > out) {
        this.$modal.msgError("本次检测数量不能大于发货数量！");
        return;
      }
      if (that.form.quantityUnqualified > that.form.quantityCheck) {
        this.$modal.msgError("不合格数量不能大于本次检测数量！");
        return;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.confirm('是否完成出货检验单编制？【完成后将不能更改】').then(function(){
            if (that.form.sourceDocId && that.form.sourceDocCode && that.form.sourceLineId) {
              that.form.status = 'FINISHED';
            }else {
              that.form.status = 'CONFIRMED';
            }
            that.submitForm();
            that.open = false;
          });
        }
        });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const oqcIds = row.oqcId || this.ids;
      this.$modal.confirm('是否确认删除出货检验单编号为"' + oqcIds + '"的数据项？').then(function() {
        return delOqc(oqcIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleSelectProduct(){
      this.$refs.itemSelect.showFlag = true;
    },
    //物料选择弹出框
    onItemSelected(obj){
        if(obj !== undefined && obj !== null){
          this.form.itemId = obj.itemId;
          this.form.itemCode = obj.itemCode;
          this.form.itemName = obj.itemName;
          this.form.specification = obj.specification;
          this.form.unitOfMeasure = obj.unitOfMeasure;
          this.form.batchCode = obj.batchCode;
          this.form.clientId = obj.clientId;
          this.form.clientCode = obj.clientCode;
          this.form.clientName = obj.clientName;
          this.form.quantityOut = obj.quantitySalse;
          this.form.itemColor=obj.itemColor;
          this.form.itemBrand=obj.itemBrand;
          this.form.itemModel=obj.itemModel;
          this.form.itemTechReq=obj.itemTechReq;
        }
    },
    handleSelectClient(){
      this.$refs.clientSelect.showFlag = true;
    },
    //客户选择弹出框
    /*onClientSelected(obj){
        if(obj != undefined && obj != null){
          this.form.clientId = obj.clientId;
          this.form.clientCode = obj.clientCode;
          this.form.clientName = obj.clientName;
        }
    },*/
    /** 导出按钮操作 */
    handleExport() {
      this.download('qc/oqc/export', {
        ...this.queryParams
      }, `oqc_${new Date().getTime()}.xlsx`)
    },
    //自动生成编码
    handleAutoGenChange(autoGenFlag){
      if(autoGenFlag){
        genCode('OQC_CODE').then(response =>{
          this.form.oqcCode = response;
        });
      }else{
        this.form.oqcCode = null;
      }
    },
    // 结果统计回显
    handleReview() {
      getOqc(this.form.oqcId).then(response => {
        this.form = response.data;
      });
    },
    handleSelectUser(){
      this.$refs.userSelect.showFlag = true;
    },
    // 用户选择弹出框
    onUserSelected(obj){
      if(obj != undefined && obj != null){
        this.form.inspector = obj.nickName;
      }
    },
    // 获取登录用户
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
      });
    },
    handleUploaded(data) {
      this.form.attr2 = data;
    },
    handleRemoved(data) {
      this.form.attr2 = data;
    },
    // 打印
    handlePrint(row) {
      this.printvisible = true;
      this.$nextTick(() => {
        this.$refs.oqcPrint.init(row.oqcId);
      })
    },
  }
};
</script>
